package com.lqq.demo5;

public class Student {
    String name;
    int age;
    char sex;
    String address;
    Grade grade;//默认值为null

    public Student() {
    }

    public Student(String name, int age, char sex, String address, Grade grade) {
        this.name = name;
        this.age = age;
        this.sex = sex;
        this.address = address;
        this.grade = grade;
    }

    public void print(){
        System.out.println("学生信息如下：");
        System.out.println("姓名：" + name);
        System.out.println("年龄：" + age);
        System.out.println("性别：" + sex);
        System.out.println("住址：" + address);
        if(grade == null){//因为默认值为null，直接输出会造成空指针异常，所以需要判断是否为null
            System.out.println("null");
        }else{
            grade.print();
        }
    }
}
